package com.tongfusoft.document.menu.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.tongfusoft.da.template.service.impl.DataTemplateServiceImpl;
import com.tongfusoft.document.menu.service.IDocumentMenuService;
import com.tongfusoft.spring.web.core.data.User;

@Service("documentMenuService")
public class DocumentMenuServiceImpl extends DataTemplateServiceImpl implements IDocumentMenuService{

	@Override
	public List<Map> getMenuList() {
		List<Map> menuList = super.selectList("getMenuList");
		for(Map valMap : menuList){
			valMap.put("child", getChildMenu((String)valMap.get("menuId")));
		}
		
		return menuList;
	}

	

	private List getChildMenu(String menuId){
		return super.selectList("getMenuChildList", menuId);
	}



	@Override
	public List<Map> getMenuListByUser(User user) {
		List<Map> menuList = super.selectList("getMenuListByUser",user.getPkValue());
		for(Map valMap : menuList){
			valMap.put("child", getChildMenuByUser(user,(String)valMap.get("menuId")));
		}
		
		return menuList;
	}
	
	private List getChildMenuByUser(User user,String menuId){
		Map<String,String> params = new HashMap<String,String>();
		params.put("userId", user.getPkValue());
		params.put("parentId", menuId);
		return super.selectList("getMenuChildListByUser", params);
	}
}
